/*************************************************************************
	> File Name:    log_inner_common.h
	> Author:       陈猛
	> Mail:         chen-meng@example.com
	> Created Time: 2019年10月28日 星期一 13时35分49秒
	> Description:  log库内部定义使用的头文件，定义一些常量
 ************************************************************************/
#ifndef _LOG_INNER_COMMON_H_
#define _LOG_INNER_COMMON_H_


#include <limits.h>
#include <stdio.h>
#include <string.h>
#if defined (__MACH__) && defined (__APPLE__)
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <stdint.h>

#if __GNUC__ >= 3
#define UNLIKELY(e) __builtin_expect(!!(e), 0)
#define LIKELY(e)   __builtin_expect(!!(e), 1)
#else
#define UNLIKELY(e) (e)
#define LIKELY(e) (e)
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) ((int)(sizeof(a)/sizeof(a[0])))
#endif

#ifndef UNUSED
#define UNUSED(a) ((void)(a))
#endif

enum DebugLevel
{
    LOG_DUMP  = 20,
    LOG_DEBUG = 40,
    LOG_INFO  = 60,
    LOG_WARN  = 80,
    LOG_ERROR = 100,
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef void (*SFLogFunction)(const char *file, int file_len, const char *func, int func_len, int line, int level, const char *format, ...);

extern SFLogFunction __logprintf;

#ifdef __cplusplus
}
#endif // __cplusplus

extern "C"
void _safety_log_out(const char *file, int file_len, const char *func, int func_len, int line, int level, const char *format, ...);

#define GEN_Printf(level, fmt, arg...) \
    do{ \
        _safety_log_out(__FILE__, sizeof(__FILE__)-1, __FUNCTION__, sizeof(__FUNCTION__)-1, __LINE__, level, fmt, ##arg); \
    }while(0)

#ifdef USE_LOG_LEVEL_COLOR
    #define TCS_NONE            "\e[0m"
    #define TCS_BLACK           "\e[0;30m"
    #define TCS_BOLD_BLACK      "\e[1;30m"
    #define TCS_RED             "\e[0;31m"
    #define TCS_BOLD_RED        "\e[1;31m"
    #define TCS_GREEN           "\e[0;32m"
    #define TCS_BOLD_GREEN      "\e[1;32m"
    #define TCS_BROWN           "\e[0;33m"
    #define TCS_YELLOW          "\e[1;33m"
    #define TCS_BLUE            "\e[0;34m"
    #define TCS_BOLD_BLUE       "\e[1;34m"
    #define TCS_PURPLE          "\e[0;35m"
    #define TCS_BOLD_PURPLE     "\e[1;35m"
    #define TCS_CYAN            "\e[0;36m"
    #define TCS_BOLD_CYAN       "\e[1;36m"
    #define TCS_GRAY            "\e[0;37m"
    #define TCS_WHITE           "\e[1;37m"
    #define TCS_BOLD            "\e[1m"
    #define TCS_UNDERLINE       "\e[4m"
    #define TCS_BLINK           "\e[5m"
    #define TCS_REVERSE         "\e[7m"
    #define TCS_HIDE            "\e[8m"
    #define TCS_CLEAR           "\e[2J"
    #define TCS_CLRLINE         "\e[1K\r"
#else
    #define TCS_NONE
    #define TCS_BLACK
    #define TCS_BOLD_BLACK
    #define TCS_RED
    #define TCS_BOLD_RED
    #define TCS_GREEN
    #define TCS_BOLD_GREEN
    #define TCS_BROWN
    #define TCS_YELLOW
    #define TCS_BLUE
    #define TCS_BOLD_BLUE
    #define TCS_PURPLE
    #define TCS_BOLD_PURPLE
    #define TCS_CYAN
    #define TCS_BOLD_CYAN
    #define TCS_GRAY
    #define TCS_WHITE
    #define TCS_BOLD
    #define TCS_UNDERLINE
    #define TCS_BLINK
    #define TCS_REVERSE
    #define TCS_HIDE
    #define TCS_CLEAR
    #define TCS_CLRLINE
#endif

#endif // _LOG_INNER_COMMON_H_

